package com.tpfinal.agenda.core.mysqlrequests;

import java.sql.DriverManager;

import com.tpfinal.agenda.core.AgendaConfig;

public class MySQL {

	public static final String MYSQL_COLUMN_ID = "id";
	public static final String MYSQL_COLUMN_TIPO = "tipo";
	public static final String MYSQL_COLUMN_NOMBRE_RAZON = "nombre_razon";
	public static final String MYSQL_COLUMN_DIRECCION = "direccion";
	public static final String MYSQL_COLUMN_CP = "cp";
	public static final String MYSQL_COLUMN_TELEFONO = "telefono";
	public static final String MYSQL_COLUMN_EMAIL = "email";
	public static final String MYSQL_COLUMN_TELEFONO_MOVIL = "telefono_movil";
	public static final String MYSQL_COLUMN_FECHA_NACIMIENTO = "fecha_nacimiento";
	public static final String MYSQL_COLUMN_WEB = "web";
	public static final String MYSQL_COLUMN_RUBROS = "rubros";

	public static final String MYSQL_CONTACT_TYPE_COMPANY = "E";
	public static final String MYSQL_CONTACT_TYPE_PERSON = "P";

	// para las Cities
	public static final String MYSQL_COLUMN_LOCALIDAD = "localidad";
	public static final String MYSQL_COLUMN_PROVINCIA = "provincia";
	public static final String MYSQL_COLUMN_DDN = "prefijo_ddn";

	private static MySQL instance;

	public static MySQL get() {
		if (instance == null) {
			instance = new MySQL();
		}
		return instance;
	}

	public java.sql.Connection getConnection() {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			java.sql.Connection conn = DriverManager.getConnection(String
					.format("jdbc:mysql://%s/%s", AgendaConfig.get()
							.getServer(), AgendaConfig.get().getDbName()),
					AgendaConfig.get().getUser(), AgendaConfig.get()
							.getPassword());
			return conn;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
